import { defineStore } from 'pinia'
import { getRedCount as getRedCountApi, pageList as pageListApi } from '@/api/front/message';
import useUserStore from '@/store/modules/user';
import { getToken } from '@/utils/auth';
import { MessageVO } from '@/api/front/message/types';
import { AxiosPromise } from 'axios';


export const useMessageStore = defineStore('messageStore', () => {
    const userStore = useUserStore();
    // 红点列表
    const redCount = ref<number[]>([]);
    const redTotal = ref<number>(0);

    // 获取消息红点的列表
    const getRedCount = async () => {
        // 校验存在用户信息及token就发送请求
        if (userStore.userId && getToken()) {
            const res = await getRedCountApi();
            redCount.value = res.data;
            redTotal.value = res.data[0]
        }
    };


    return {
        redCount,
        redTotal,
        getRedCount
    }
});

export default useMessageStore;
